package cl.uchile.sti.authorization.dao;

import cl.uchile.sti.authorization.model.Menu;
import cl.uchile.sti.authorization.model.Pagina;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Julio Villane
 * Date: 12-12-12
 * Time: 08:51 AM
 */
public class MenuDao {

    private static EntityManager entityManager = cambiarPorSpring.getEntityManager();

    private MenuDao(){ }

    public static Menu findID(Long id){
        return entityManager.find(Menu.class, id);
    }
    public static List<Menu> find(){
        Query q =  entityManager.createQuery("select m from Menu m ");
        List <Menu> resultado=q.getResultList();
        return resultado;
    }
    public static Menu save(Menu menu) {
        if (menu.getId() == null) {
            entityManager.persist(menu);
            return menu;
        } else {
            return entityManager.merge(menu);
        }
    }

    public static void delete(Menu menu){
        entityManager.remove(menu);
    }
}
